import datetime

from django.db import models
from django.utils import timezone

from tbitem.models import WadeMiaoKouLing


def get_foo():
    return WadeMiaoKouLing.objects.get_or_create(id=0)[0].id
# Create your models here.
class MS_USER(models.Model):
    ID =models.AutoField(primary_key=True)
    USERNAME = models.CharField(max_length=20, blank=False, default=None, unique=True, null=False)
    PASSWORD = models.CharField(max_length=20,null=False, blank=False)
    nickName = models.CharField(max_length=20, null=False, blank=False, default='怎么样好用吗')
    intro = models.CharField(max_length=40, null=True, blank=True, default='介绍一下自己')
    userIMG = models.ImageField(upload_to='userHEAD/', default=f'userHEAD/{datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")+"1"}.jpg', blank=True, null=True)#禁止空  模板的名称，对应到前台的页面名称进行跳转
    userLevel =models.IntegerField(null=False,blank=False,default=1)
    date = models.DateTimeField(auto_now_add=True,blank=True,null=True)  # 操作更新时间,datetime.datetime.now()
    hasTimes = models.IntegerField(null=False,default=0,blank=False)
    UPDATED_TIME = models.DateTimeField(auto_now_add=True)
    ms_user_miaokouling = models.ForeignKey('tbitem.WadeMiaoKouLing', default=get_foo, verbose_name='选择对应的喵口令配置',
                                                   on_delete=models.DO_NOTHING)
    def __str__(self):
        return f"{self.USERNAME},调用次数还剩余:{self.hasTimes} 次"
    class Meta:
        verbose_name = '管理用户'
        verbose_name_plural = verbose_name